package com.lcx.movie.controller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lcx.movie.common.Rep;
import com.lcx.movie.entity.UserBan;
import com.lcx.movie.service.UserBanService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 李丽君
 * @version 1.0
 * @Description 用户封禁控制类
 * @date 2025/3/17 18:30
 */
@RestController
@CrossOrigin(origins = "*")
public class UserBanController {
    @Autowired
    private UserBanService userBanService;
    /**
     * 新增封禁用户
     * @param userId 用户id
     * @return 受影响的行数
     */
    @PostMapping("/insertUserBan")
    public String insertUserBan(@Param("userId") int userId){
        int insertUserBan = userBanService.insertUserBan(userId);
        if (insertUserBan >0){
            return "insert success";
        }else {
            return "insert fail";
        }
    }
    /**
     * 根据用户id修改封禁状态为申请解封中
     * @param userId 用户id
     * @return 受影响的行数
     */
    @GetMapping("/updateUserBan")
    public String updateUserBan(@Param("userId") int userId){
        int updateUserBan = userBanService.updateUserBan(userId);
        if (updateUserBan >0){
            return "update success";
        }else {
            return "update fail";
        }
    }

    /**
     * 根据用户名查询封禁用户
     * @param userName 用户名
     * @return 封禁用户集合
     */
    @GetMapping("/selectUserBan")
    public Rep selectUserBan(@Param("page") Integer page,@Param("pageSize") Integer pageSize
            ,@Param("userName") String userName){
        // 开启分页
        PageHelper.startPage(page,pageSize);
        // 执行查询
        List<UserBan> userBans = this.userBanService.selectUserBan(userName);
        PageInfo<UserBan> userBanPageInfo=new PageInfo<>(userBans);
        return new Rep().addData("userBanPageInfo",userBanPageInfo);
    }
    /**
     * 删除封禁记录
     * @param banId 封禁id
     * @return 受影响的行数
     */
    @GetMapping("/deleteUserBan")
    public String deleteUserBan(@Param("banId") Integer banId){
        int deleteUserBan = this.userBanService.deleteUserBan(banId);
        if (deleteUserBan >0){
            return "delete success";
        }else {
            return "delete fail";
        }
    }


}
